<template>
  <el-container style="height: 100vh;">
    <el-aside width="200px">
      <el-menu router unique-opened :default-active="$route.path">
        <el-submenu index="categories">
          <template slot="title">
            <i class="el-icon-menu"></i>分类管理
          </template>
          <el-menu-item-group>
            <template slot="title">分类</template>
            <el-menu-item index="/categories">新建分类</el-menu-item>
            <el-menu-item index="/categories/list">分类列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="items">
          <template slot="title">
            <i class="el-icon-menu"></i>物品管理
          </template>
          <el-menu-item-group>
            <template slot="title">物品</template>
            <el-menu-item index="/items">新建物品</el-menu-item>
            <el-menu-item index="/items/list">物品列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="heroes">
          <template slot="title">
            <i class="el-icon-menu"></i>英雄管理
          </template>
          <el-menu-item-group>
            <template slot="title">英雄</template>
            <el-menu-item index="/heroes">新建英雄</el-menu-item>
            <el-menu-item index="/heroes/list">英雄列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="articles">
          <template slot="title">
            <i class="el-icon-menu"></i>文章管理
          </template>
          <el-menu-item-group>
            <template slot="title">文章</template>
            <el-menu-item index="/articles">新建文章</el-menu-item>
            <el-menu-item index="/articles/list">文章列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="advertise">
          <template slot="title">
            <i class="el-icon-menu"></i>广告管理
          </template>
          <el-menu-item-group>
            <template slot="title">广告</template>
            <el-menu-item index="/advertise">新建广告</el-menu-item>
            <el-menu-item index="/advertise/list">广告列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="admin_users">
          <template slot="title">
            <i class="el-icon-menu"></i>用户管理
          </template>
          <el-menu-item-group>
            <template slot="title">用户</template>
            <el-menu-item index="/admin_users">新建用户</el-menu-item>
            <el-menu-item index="/admin_users/list">用户列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logoutHandle">退出登录</el-dropdown-item>
            <el-dropdown-item>新增</el-dropdown-item>
            <el-dropdown-item>删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>王小虎</span>
      </el-header>

      <el-main>
        <router-view :key="$route.path" />
      </el-main>
    </el-container>
  </el-container>
</template>


<script>
export default {
  data() {
    return {
    };
  },
  methods: {
    async logoutHandle() {
      const confirmRes = await this.$confirm("您确认要退出登录吗?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).catch(err=> err)
      if (confirmRes === "confirm") {
        localStorage.removeItem("token");
        this.$router.push("/login");
      }
    }
  }
};
</script>

<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
html,
body {
  margin: 0;
  padding: 0;
}
</style>
